package com.pyz.thread.version.threadlocal;

import com.pyz.thread.entity.Ticket;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class V1Main {

    public static ThreadLocal<List<Ticket>> localTickets = ThreadLocal.withInitial(new Supplier<List<Ticket>>() {
        private String name = "demo";

        @Override
        public List<Ticket> get() {
            return new ArrayList<>();
        }
    });

    public static void main(String[] args) {
        ArrayList<Ticket> tickets = new ArrayList<Ticket>();
        for (int i = 0; i < 1000000; i++) {
            Ticket ticket = new Ticket("车票" + i, i);
            tickets.add(ticket);
        }
        System.out.println("抢票开始-----start");
        for (int i = 0; i < 100; i++) {
            new Thread(new TicketGrabber(tickets, localTickets)).start();
        }
    }
}
